home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / LIB / PUSHPOP.C < prev    next >
C/C++ Source or Header  |  1993-06-15  |  3KB  |  110 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    p u s h p o p . c                                               */
  3. /*                                                                    */
  4. /*    Directory functions for UUPC/extended                           */
  5. /*                                                                    */
  6. /*    Changes Copyright (c) 1989 - 1993 by Kendra Electronic          */
  7. /*    Wonderworks.   All rights reserved except as explicitly         */
  8. /*    granted by the UUPC/extended license.                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Id: pushpop.c 1.5 1993/06/15 12:37:16 ahd Exp $
  13.  *
  14.  *    $Log: pushpop.c $
  15.  *     Revision 1.5  1993/06/15  12:37:16  ahd
  16.  *     Correct compile warning message about const assignment
  17.  *
  18.  *     Revision 1.4  1993/06/15  12:18:06  ahd
  19.  *     Save pushed directory name for debugging
  20.  *
  21.  *     Revision 1.3  1993/06/13  14:06:00  ahd
  22.  *     Insure directories PUSHED are POPPED
  23.  *
  24.  * Revision 1.2  1992/11/22  21:06:14  ahd
  25.  * Use strpool for memory allocation
  26.  *
  27.  */
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*                        System include files                        */
  31. /*--------------------------------------------------------------------*/
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <sys/types.h>
  36.  
  37. #include <direct.h>
  38. #include <string.h>
  39.  
  40. /*--------------------------------------------------------------------*/
  41. /*                    UUPC/extended include files                     */
  42. /*--------------------------------------------------------------------*/
  43.  
  44. #include "lib.h"
  45. #include "pushpop.h"
  46.  
  47. #define MAXDEPTH 10
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                          Global variables                          */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. static char *dirstack[MAXDEPTH];
  54. static depth = 0;
  55.  
  56. currentfile();
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*            Change to a directory and push on our stack             */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. void PushDir( const char *directory )
  63. {
  64.    char cwd[FILENAME_MAX];
  65.    if ( depth >= MAXDEPTH )
  66.       panic();
  67.  
  68. #ifdef __TURBOC__
  69.    dirstack[depth] = newstr( getcwd( cwd  , FILENAME_MAX ));
  70. #else
  71.  
  72. #ifdef __GNUC__
  73.    dirstack[depth] = newstr( getcwd( cwd , FILENAME_MAX ) );
  74. #else
  75.    dirstack[depth] = newstr( _getdcwd( 0, cwd , FILENAME_MAX ) );
  76. #endif
  77.  
  78. #endif
  79.  
  80.  
  81.    if (dirstack[depth] == NULL )
  82.    {
  83.       printerr("getcwd");
  84.       panic();
  85.    }
  86.  
  87.    CHDIR( directory );
  88.  
  89.    E_cwd = equal(directory,".") ? dirstack[depth] : (char *) directory;
  90.  
  91.    depth++;
  92.    return;
  93.  
  94. } /* PushDir */
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*               Return to a directory saved by PushDir               */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. void PopDir( void )
  101. {
  102.    if ( depth == 0 )
  103.       panic();
  104.  
  105.    CHDIR( dirstack[--depth] );
  106.    E_cwd = dirstack[depth];
  107.    return;
  108.  
  109. } /* PopDir */
  110.